function DateFormat(pattern, time) {
    // console.log(pattern);  // "YYYY-MM-DD hh:mm:ss"

    if (time != undefined) { // 没有参数
        var date = new Date(time);
    } else {  //没有参数
        var date = new Date();
    }

    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();

    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();

    return pattern.replace("YYYY", year).replace("MM", beautify(month)).replace("DD", beautify(day)).replace("hh", beautify(hour)).replace("mm", beautify(minute)).replace("ss", beautify(second));


}

function beautify(num) {
    return num < 10 ? "0" + num : num;
}